package com.soft.javase.ch03.statics;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/20
 *
 * 实例块
 * 1.语法：
 *  * {
 *  *      //代码
 *  * }
 *  * 2.随着对象的创建而加载实例块
 *  * 3.允许存在多个实例块，按照顺序进行加载
 */
public class InstanceBlockDemo {

    private String name;
    private int age;

    //实例块
    {
        System.out.println("实例块");
    }

    public static void main(String[] args) {
        InstanceBlockDemo instanceBlockDemo1 = new InstanceBlockDemo();
        instanceBlockDemo1.name = "张三";
        System.out.println("instanceBlockDemo1.name="+instanceBlockDemo1.name);

        InstanceBlockDemo instanceBlockDemo2 = new InstanceBlockDemo();
        instanceBlockDemo2.name = "李四";
        System.out.println("instanceBlockDemo2.name="+instanceBlockDemo2.name);
    }
}
